#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N=1e5+10;
int sign[N];
int x, y; 
queue<int> q;
int ret=1e6;
void bfs()
{
	while(q.size())
	{
		int num=q.front(); q.pop();
		for(int i=1; i<=3; i++)
		{
			int j=0;
			if(i==1) j=num+1;
			else if(i==2) j=num-1;
			else j=num*2;
			if(j < 1 || j > N) continue;
			if(sign[j] != -1) continue;
			sign[j]=sign[num]+1;
			if(j==y) 
			{
				ret=min(ret, sign[j]);
				continue;
			}
			q.push(j);
		}
	}
}
int main()
{
	int n; cin>>n;
	while(n--)
	{
		memset(sign, -1, sizeof sign);
		ret=1e6;
		cin>>x>>y;
		q.push(x);
		sign[x]=0;
		bfs();
		cout<<ret<<endl;
		while(!q.empty()) q.pop();
	}
	return 0;
}
